/************************************************************************************
 *                                                                                  *
 *                                                                                  *
 ************************************************************************************/
package jMiiEditor.gui.swingintrospection;

import javax.swing.JSpinner;
import org.apache.log4j.Logger;
import jMiiEditor.gui.JMiiEditorMainJFrame;
import jMiiEditor.mii.Mii;
import jMiiEditor.mii.introspection.MiiGetterIntrospection;
import jMiiEditor.mii.introspection.MiiGetterIntrospectionItem;
import cx.ath.choisnet.lang.introspection.IntrospectionException;
import cx.ath.choisnet.lang.introspection.method.IntrospectionItem;
import cx.ath.choisnet.swing.introspection.AbstractSwingIntrospectorObjectInterface;
import cx.ath.choisnet.swing.introspection.DefaultComponentInitializer;
import cx.ath.choisnet.swing.introspection.FrameFieldPopulator;
import cx.ath.choisnet.swing.introspection.ObjectPopulator;
import cx.ath.choisnet.swing.introspection.SwingIntrospectorException;
import cx.ath.choisnet.swing.introspection.SwingIntrospectorRootItem;

/**
 * @author CC
 */
public class MiiSwingIntrospectorObjectInterface
    extends AbstractSwingIntrospectorObjectInterface<
                JMiiEditorMainJFrame,
                Mii,
                MiiGetterIntrospectionItem
                >
{    
    private static Logger slogger = Logger.getLogger(MiiSwingIntrospectorObjectInterface.class);
    public MiiSwingIntrospectorObjectInterface()
    {
        this( new MiiGetterIntrospection() );
    }
    
    private MiiSwingIntrospectorObjectInterface(MiiGetterIntrospection miiGetterIntrospection)
    {
        super(
                JMiiEditorMainJFrame.class,
                miiGetterIntrospection,
                new DefaultComponentInitializer<Mii,MiiGetterIntrospectionItem>(miiGetterIntrospection)
                {
                    public void setModel( 
                            JSpinner                jSpinner, 
                            IntrospectionItem<?>    iItem,
                            String                  beanname 
                            )
                    {
                        // Does nothing ! TODO: move here code for Day JSpinner
                        if( beanname.equals( "Day" )) {
//                            List<String> days = new ArrayList<String>(32);
//                            days.add( "-" );
//                            for(int i=1;i<32;i++) {
//                                days.add( Integer.toString( i ));
//                            }
//                            SpinnerModel model = new SpinnerListModel(days);
//                            jSpinner.setModel(model);
                            slogger.warn("Not yet implemented setModel() for Day");
                        }
                    }
                }
                );
    }

//    /**
//     * @return the MiiGetterIntrospection object
//     */
//    // TO DO: remove this, just for testing
//    public MiiGetterIntrospection JUST_FOR_TESTING_getMiiGetterInspection()
//    {
//        Introspection<Mii, MiiGetterIntrospectionItem> miiGetterIntrospection = super.getIntrospection();
//
//        return MiiGetterIntrospection.class.cast( miiGetterIntrospection );
//    }

    @Override
    public ObjectPopulator<JMiiEditorMainJFrame,Mii,MiiGetterIntrospectionItem> getObjectPopulator(
            final JMiiEditorMainJFrame  frame,
            final Mii                   object
            )
    {
        final SwingIntrospectorMiiPopulater<JMiiEditorMainJFrame> mp 
        = new SwingIntrospectorMiiPopulater<JMiiEditorMainJFrame>( object, frame );

        return new ObjectPopulator<JMiiEditorMainJFrame,Mii,MiiGetterIntrospectionItem>()
        {
            @Override
            public void populateObject(
                    MiiGetterIntrospectionItem  entry,
                    SwingIntrospectorRootItem<JMiiEditorMainJFrame>   rootItem
                    )
            throws  SwingIntrospectorException,
                    IntrospectionException
            {
                mp.populate( entry, rootItem );
            }
        };
    }

    @Override
    public FrameFieldPopulator<JMiiEditorMainJFrame, Mii> getFrameFieldPopulator(
            JMiiEditorMainJFrame    frame,
            Mii                     object
            )
    {
        return new MiiFrameFieldPopulator<JMiiEditorMainJFrame>( frame, object );
    }

}
